package org.discala.samples.complex.chef.appliance

import org.discala.samples.complex.domain.PreparationMethod._
import org.discala.scopes.Singleton

/**
 * A custom provider definition for appliances. Similar to a factory, but more
 * tightly bound with the di framework. A good demonstration of an assisted provider.
 *
 * @author Chris Turner
 */
private[chef] class ApplianceProvider(scope: Singleton) {

  val provider = (method: PreparationMethod) => {
    method match {
      case Bake => oven()
      case Grill => grill()
      case Boil => hob()
      case Fry => deepFatFryer()
      case Toast => toaster()
      case Stand => shelf()
      case Chill => fridge()
      case Freeze => freezer()
    }
  }

  private val oven = scope.singleton(() => new Oven)
  private val grill = scope.singleton(() => new Grill)
  private val hob = scope.singleton(() => new Hob)
  private val deepFatFryer = scope.singleton(() => new DeepFatFryer)
  private val toaster = scope.singleton(() => new Toaster)
  private val shelf = scope.singleton(() => new Shelf)
  private val fridge = scope.singleton(() => new Fridge)
  private val freezer = scope.singleton(() => new Freezer)
}